/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entity;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author antonio
 */
@Entity
@Table(name = "Factory")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Factory.findAll", query = "SELECT f FROM Factory f"),
    @NamedQuery(name = "Factory.findByBuilding", query = "SELECT f FROM Factory f WHERE f.building = :building")})
public class Factory implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @NotNull
    @Column(name = "building")
    private Integer building;
    @JoinColumn(name = "building", referencedColumnName = "unit", insertable = false, updatable = false)
    @OneToOne(optional = false)
    private Building building1;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "factory1")
    private Collection<Manufacture> manufactureCollection;

    public Factory() {
    }

    public Factory(Integer building) {
        this.building = building;
    }

    public Integer getBuilding() {
        return building;
    }

    public void setBuilding(Integer building) {
        this.building = building;
    }

    public Building getBuilding1() {
        return building1;
    }

    public void setBuilding1(Building building1) {
        this.building1 = building1;
    }

    @XmlTransient
    public Collection<Manufacture> getManufactureCollection() {
        return manufactureCollection;
    }

    public void setManufactureCollection(Collection<Manufacture> manufactureCollection) {
        this.manufactureCollection = manufactureCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (building != null ? building.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Factory)) {
            return false;
        }
        Factory other = (Factory) object;
        if ((this.building == null && other.building != null) || (this.building != null && !this.building.equals(other.building))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entity.Factory[ building=" + building + " ]";
    }
    
}
